package tp.pr3.instructions;

import java.util.StringTokenizer;

import tp.pr3.NavigationModule;
import tp.pr3.RobotEngine;
import tp.pr3.instructions.exceptions.InstructionExecutionException;
import tp.pr3.instructions.exceptions.WrongInstructionFormatException;
import tp.pr3.items.ItemContainer;

public class RadarInstruction
extends java.lang.Object
implements Instruction {
	
	private NavigationModule navigation;
	
	public Instruction parse(java.lang.String cad) throws WrongInstructionFormatException
	{
		StringTokenizer instructionToken = new StringTokenizer(cad);
		if (instructionToken.countTokens() != 1)
			throw new WrongInstructionFormatException();
		
		String actionString = instructionToken.nextToken();	
		if(!actionString.equalsIgnoreCase("RADAR"))
			throw new WrongInstructionFormatException();
		
		return new RadarInstruction();
	} 
	public void execute() throws InstructionExecutionException
	{
		try{
			navigation.scanCurrentPlace();
		}catch(Exception e){
			throw new InstructionExecutionException(e);
		}
	}          
	
	public java.lang.String getHelp()
	{
		return("RADAR");
	}
	
	public void configureContext(RobotEngine engine,
            NavigationModule navigation,
            ItemContainer robotContainer)
	{
		this.navigation=navigation;
	}
}
